<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no"/>
    <title>弹出购买页面</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css"/>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css"/>
    <style>
        body {
            background: transparent;
            font-size: 14px;
            overflow: auto;

        }

    </style>
</head>

<body>
<div class="contain dispalyNone-unImportant">
    <div class="aui-mask"></div>
    <footer class="aui-nav z-index99 height-auto " tapmode onclick="openToTwo('')">

        <div class=" " id="goodInfo-content">


        </div>
        <div class="aui-btn sureBtn aui-btn-block aui-btn-danger radius-0" tapmode onclick="btnCheck();"
             style="height: 55px;line-height: 55px;font-size: 16px;padding-top:0;">立即购买
        </div>
    </footer>
</div>
<script id="goodInfo-template" type="text/x-dot-template">
    <ul class="aui-list-view " style="margin-bottom: 45px;">
        <li class="aui-list-view-cell aui-img">
            <img class="aui-img-object aui-pull-left" src="{{=it.goods_img}}">
            <div class="aui-img-body">
                <p class="aui-ellipsis-2">{{=it.goods_name}}</p>
                <p class="aui-ellipsis-2 aui-text-danger font-weight-700 aui-margin-t-5">￥{{=it.show_price}}元</p>
            </div>
        </li>
        <li class="aui-list-view-cell aui-img ">
            <div class="line-height-34">
                <div class="aui-col-xs-6">
                    <p class="font-black"><h6>选择购买数量</h6></p>
                    <p class=""><h6>￥<em class="price">{{=it.show_price}}</em> x <em
                        class="count font-weight-700 font-black">1</em>=<em
                        class=" totalMoney font-weight-700 aui-text-danger ">{{=it.show_price}}</em>元</h6></p>
                </div>
                <div class="mui-numbox aui-col-xs-6 aui-pull-right" data-numbox-step='1' data-numbox-min='1'
                     data-numbox-max='50'>
                    <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
                    <input id="countInput" class="mui-input-numbox" type="number" value="1"/>
                    <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
                </div>
            </div>
        </li>
        <li class="aui-list-view-cell ">
            <div class="aui-flex-item-12 ">
                {{? it.vmoney_user>0}}
                <div class="  aui-pull-right aui-margin-0">
                    <h6 class="aui-pull-left">订单完成赠送</h6>
                    <input type="hidden" value="{{=it.vmoney_user}}" class="my-song-jifen">
                    <em class=" shangjing-color2 font-szie-18  "><em class="song-jifen">{{=it.vmoney_user}}</em>积分</em>
                </div>
                {{??}}

                <div class="  aui-pull-right aui-margin-0 ">
                    <input type="hidden" value="{{=it.vmoney_unbackable}}"  class="my-di-jifen">
                    <em>可用</em>
                    <em class=" shangjing-color2 font-szie-18  "><em class="di-jifen">{{=it.vmoney_unbackable}}</em>积分</em>
                    <em>抵<em class="di-jifen2">{{=it.vmoney_unbackable}}</em>元</em>
                </div>
                {{}}}
            </div>

        </li>
    </ul>
    <!--<div class="aui-btn   aui-btn-block radius-0 colorWhite  noBorder " tapmode onclick="goToOrder('{{=it.goods_id}}')" style="background: #00a9e3;height: 55px;line-height: 55px;font-size: 16px;" >立即购买</div>-->
</script>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.3.js"></script>
<script type="text/javascript" src="../script/index.js"></script>
<script type="text/javascript" src="../script/mui.min.js"></script>
<script type="text/javascript">
    var goodId, companyName, money, orderId, orderNo, count = 1;
    var vmoney = "", type = "";
    apiready = function () {
        api.parseTapmode();
        goodId = api.pageParam.goodId;
        type = api.pageParam.type;
        if (type == "addCar") {
            $(".sureBtn").removeClass('aui-btn-danger').addClass('aui-btn-warning').text("加入购物车")
        } 

        $(".payMoney").text(money)
        //验证地址
        getStorageAll();
        //商品订单列表
//        alert(orderId)
        getGoodInfo();
    }

    $(document).on("change", "#countInput", function () {
        count = $(this).val();
        $(this).closest("li").find(".count").text(count);
        var price = $(this).closest("li").find(".price").text();
        var total = price * count;
        $(this).closest("li").find(".totalMoney").text(total.toFixed(2));
        $(".vmoney").text((count * vmoney).toFixed(2));
        $(".song-jifen").text(($(".my-song-jifen").val()*count).toFixed(2))
        $(".di-jifen").text(($(".my-di-jifen").val()*count).toFixed(2))
        $(".di-jifen2").text(($(".my-di-jifen").val()*count).toFixed(2))
    })
    $(".aui-mask").click(function () {
        closeFrame();
    })

    function btnCheck(){
        if (type == "addCar") {
            addCar();
        }else{
            goToOrder();
        }
    }

    function getGoodInfo() {
        showLoading()
        var url = "goods/info";
        var data = {};
        data["goods_id"] = goodId;
        getStorageAll();
//        alert(JSON.stringify(data))
        ajaxRequest(url, 'get', data, function (ret, err) {
            $(".contain").show();
            var content = $api.byId('goodInfo-content');
            var tpl = $api.byId('goodInfo-template').text;
            var tempFn = doT.template(tpl);
            $api.html(content, '');
            $api.html(content, tempFn(ret.data));
            hideLoading();
            mui('.mui-numbox').numbox();
            vmoney = ret.data.vmoney_user > 0 ? ret.data.vmoney_user : ret.data.vmoney_unbackable;
        });
    }
    function goToOrder() {
        var goodJson = "["
        goodJson += '{"goods_id":' + goodId + ",";
        goodJson += '"goods_number":' + count;
        goodJson += "}";
        goodJson += "]"
        getStorageAll();
        if (!user_id) {
            api.toast({
                msg: "还没登录,请先登录"
            })
            setTimeout(function () {
                api.openWin({
                    name: 'loginPass_win',
                    url: 'loginPass_win.html'
                })
            }, 1500)

        } else {
            api.openFrame({
                bgColor: 'rgba(0,0,0,0)',
                name: 'orderConfirm_win',
                url: 'orderConfirm_win.html',
                bounces: false,
                rect: {
                    x: 0,
                    y: 0,
                    w: 'auto',
                    h: 'auto'
                },
                pageParam: {
                    goodId: goodId,
                    orderType: "singleGood",
                    count: count,
                    goodOrderInfo: goodJson
                }
            });
        }
    }
    function addCar() {
        var goodJson = "["
        goodJson += '{"goods_id":' + goodId + ",";
        goodJson += '"goods_number":' + count;
        goodJson += "}";
        goodJson += "]"
        getStorageAll();
        if (!user_id) {
            api.toast({
                msg: "还没登录,请先登录"
            })
            setTimeout(function () {
                api.openWin({
                    name: 'loginPass_win',
                    url: 'loginPass_win.html'
                })
            }, 1500)

        } else {
            var url = "cart/update";
            var data = {};
            data["goods"] = goodJson;
            data["is_add"] = 1;
            ajaxRequest(url, 'post', data, function (ret, err) {
                api.sendEvent({
                    name:"updateCar",
                    extra:{
                        key:true
                    }
                })
                api.toast({
                    msg: "购物车添加成功"
                })
                setTimeout(function () {
                    closeFrame();
                }, 1500)
            });
        }
    }
</script>

</html>
